package com.imm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imm.common.Result;
import com.imm.pojo.Category;
import com.imm.service.ICategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private ICategoryService categoryService;

    /**
     * 分页查询
     * @param page 页数
     * @param pageSize 页大小
     * @return 响应
     */
    @GetMapping("/page")
    public Result<Page<Category>> page(int page, int pageSize) {
        return categoryService.pageCategory(page, pageSize);
    }

    /**
     * 新增分类
     * @param category 分类实体类
     * @return 响应
     */
    @PostMapping
    public Result<String> insert(@RequestBody Category category) {
        return categoryService.insert(category);
    }

    /**
     * 批量删除
     * @param ids id数组
     * @return 响应
     */
    @DeleteMapping
    public Result<String> delete(Long ids) {
        return categoryService.delete(ids);
    }

    /**
     * 更新
     * @param category 分类实体类
     * @return 响应
     */
    @PutMapping
    public Result<String> update(@RequestBody Category category) {
        return categoryService.updateCategory(category);
    }

    /**
     * 搜索
     * @param category 实体类
     * @return 响应
     */
    @GetMapping("/list")
    public Result<List<Category>> listType(Category category) {
        return categoryService.listType(category);
    }

}
